<?php
    include_once "../../inc/config.inc.php";
    include_once '../../inc/mysql.inc.php';
    include_once "../inc/tool.inc.php";

    $template["title"] = "父版块修改";
    $template["keyword"] = "父版块修改";
    $template["description"] = "父版块修改";

    $link = connect();
    if(!isset($_GET['id']) || !is_numeric($_GET['id'])){
        skip("father_module.php", "error", "id参数错误！");  
    }
  
    $query = "select * from kuse_father_module where id = {$_GET['id']}";
    $result = execute($link, $query);
    if(!mysqli_num_rows($result)){
        skip("father_module.php", "error", "这条版块信息不存在！");
    }
    $data = mysqli_fetch_assoc($result);

    if(isset($_POST['submit'])){

        $check_flag = "update";

        // 验证填写信息是否成功 
        include_once '../inc/check_father_module.inc.php';
        
        $query = "update kuse_father_module set module_name='{$_POST['module_name']}', sort={$_POST['sort']} where id={$_GET['id']}";

        execute($link, $query);

        if(mysqli_affected_rows($link)==1){
            skip("father_module.php", "ok", "恭喜你，修改成功！");
        }else{
            skip("father_module_add.php", "error", "对不起，修改失败，请重试！");
        }
    }        
?>
<?php include_once "../inc/header.inc.php";?>

<div id="main">
    <div class="title">父版块修改 - <?php echo $data['module_name']?></div>
        <form method="post">
            <table class="au">
                <tr>
                    <td>版块名称</td>
                    <td><input name="module_name" value=<?php echo $data['module_name'] ?> type="text" /></td>
                    <td>版块名称不得为空，最大不能超过66个字符</td>
                </tr>
                <tr>
                    <td>排序</td>
                    <td><input name="sort" value=<?php echo $data['sort'] ?> type="text" /></td>
                    <td>填写一个数字即可</td>
                </tr>
            </table>

            <input type="submit" class="btn" name="submit" value="修改">
        </form>
    </div>
</div>

<?php include_once "../inc/footer.inc.php";?>